import StudySearch from '@/pages/study/search/index';
import { useModel, useNavigate } from 'alita';
import React, { useEffect, useState } from 'react';
import { checkAuthorize } from '@/utils/authorize';
import { ComplexOAUser } from '../types/type';
import { UseAuthModel } from '@/models/useAuthModel';
import { Tag, Result } from 'antd-mobile';
import HospitalManage from '../backend/hospitalManage';
import { SmileOutline } from 'antd-mobile-icons';
export default () => {
  const [tokening, setTokening] = useState<boolean>(true);
  const [tokenFail, setTokenFail] = useState<string | undefined>(undefined);
  const [authOK, setAuthOK] = useState<boolean>(false);
  const model: UseAuthModel = useModel('useAuthModel');
  const { id, name, diagnosisGroups, doctor, manageHospitals, projectManager, oaSystemLivings } = model.userInfo;
  useEffect(() => {
    checkAuthorize(
      (x) => setTokening(x),
      (y) => {
        console.log(`token检查完成，是否通过授权：${y}`);
        setAuthOK(y);
      },
      (z) => setTokenFail(z),
      model,
    );
  }, []);

  //const { justADoctor } = model;
  if (id.length < 2) {
    return <Result
      icon={<SmileOutline />}
      status='success'
      title='正在登录'
      description='正在获取你的信息...'
    />
  }

  if (manageHospitals.length > 0) {
    return <HospitalManage></HospitalManage>
  }
  return <StudySearch></StudySearch>
}